package com.wyyx.api;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.wyyx.model.Coupon;
import com.wyyx.services.CouponSelectServices;

import commons.Constants;
import commons.JsonResult;
import commons.JsonResultWriter;

/**
 * 查询我的优惠券
 */
@WebServlet("/CouponSelectServlet")
public class CouponSelectServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String userId  = request.getParameter("userId");
		CouponSelectServices couponSelectServices = new CouponSelectServices();
		List<Coupon> list = couponSelectServices.couponSelect(userId);
		JsonResult result = null;
		try {
			if(list!=null) {
				result = new JsonResult<>(list,"查询成功",Constants.STATUS_SUCCESS);
			}
			else {
				result = new JsonResult<>("查询失败",Constants.STATUS_NOTFOUND);
			}
		}catch(Exception e) {
			result = new JsonResult<>("查询异常",Constants.STATUS_EX);
		}
		JsonResultWriter.writer(response,result);
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
